package com.mc.read.common.util;

import java.util.Date;
import java.util.Random;

/**
 * 主键生成类
 * 获取14为随机数序列
 * 获取19为随机数序列
 * 获取24为随机数序列
 *
 * @author songshengqi
 * @version Id: PrimarykeyUtil.java, v 0.1 2017/1/11 17:58 songshengqi Exp $$
 */
public class PrimarykeyUtil {

    /**
     * 获取主键14位主键
     *
     * @return String 主键
     */
    public static String queryPrimarykey14(){
        String primarykey= DateUtil.format( new Date(), DateUtil.fullPatterns);
        return primarykey;
    }

    /**
     * 获取主键24位主键
     *
     * @return
     */
    public static String queryPrimarykey24(){
        String primarykey=DateUtil.format( new Date(),DateUtil.fullPatterns);
        String randNumStart= String.valueOf(PrimarykeyUtil.random(7));
        primarykey=primarykey+randNumStart;
      return primarykey;
    }


    /**
     * 获取主键30位主键
     *
     * @return
     */
    public static String queryPrimarykey30(){
        String primarykey= DateUtil.format( new Date(), DateUtil.fullPatterns);
        String randNumStart= String.valueOf(PrimarykeyUtil.random(11));
        String endNumStart= String.valueOf(PrimarykeyUtil.random(5));
        primarykey=primarykey+randNumStart+endNumStart;
        return primarykey;
    }

    /**
     * 获取主键19位主键
     *
     * @return
     */
    public static String queryPrimarykey19(){
        String primarykey= DateUtil.format( new Date(), DateUtil.fullPatterns);
        Random rand = new Random();
        String randNumStart= String.valueOf(PrimarykeyUtil.random(5));
        primarykey=primarykey+randNumStart;
        return primarykey;
    }

    /**
     * 获取随机数序列
     *
     * @param size
     * @return String 随机长度为size的字符序列
     */
    public static String random(int size){
        String randnum=new String();
        for (int i=0;i<size ;i++){
            Random rand = new Random();
            randnum=randnum+String.valueOf(rand.nextInt(9));
        }
       return randnum;
    }
    /**
     *@Author:LiuHao
     *@Date:15:30 2018/5/3
     *获取8位字符串
    **/
    public static String queryPrimarykey8(){
        String result="";
        for(int i=0;i<10;i++){
            int intVal=(int)(Math.random()*26+97);
            result=result+(char)intVal;
        }
        return result;
    }


}
